package force;

import backbone.IForceable;
import main.Simulation;


/**
 * Force of Gravity.
 * @author Paul
 * @author Lance
 *
 */
public class Gravity extends GlobalForce {

    private static final String NAME = "Gravity";

    /**
     * Dictates gravity direction.
     */
    private double myDirection;

    /**
     * @param direction gravity direction
     * @param magnitude gravity magnitude
     */
    public Gravity(final double direction, final double magnitude) {
        super(magnitude, NAME);
        myDirection = direction;
    }

    /**
     * @param newDirection direction of Gravity
     */
    public final void setDirection(final double newDirection) {
        myDirection = newDirection;
    }

    @Override
    public void update (Simulation canvas, double dt) {
        Force f = new Force(myDirection, getMagnitude());
        for (IForceable forceable : getForceables()) {
            forceable.applyForce(f);
        }
    }

}
